﻿using System;
using System.Collections.Generic;
using System.Text;

namespace C11_Ex01_4
{
    public class Program
    {
        public static void Main()
        {
            string inputString;
            bool binaryInput = true;

            System.Console.WriteLine("Please enter a binary number of 7 digits length.");
            inputString = System.Console.ReadLine();

            for (int i = 0; binaryInput && i < inputString.Length; i++)
            {
                if (inputString[i] != '0' && inputString[i] != '1')
                {
                    binaryInput = false;
                }
            }

            System.Console.WriteLine("The input is{0}binary number.", binaryInput ? " a " : " not a ");
            System.Console.WriteLine("The input is{0}7 digits long.", inputString.Length == 7 ? " " : " not ");

            if (binaryInput && inputString.Length == 7)
            {
                int number = 0;
                int multiplier = 1;

                for (int i = inputString.Length - 1; i >= 0;  i--)
                {
                    number += int.Parse(inputString[i].ToString()) * multiplier;
                    multiplier *= 2;
                }

                System.Console.WriteLine("The number is {0}", number);
                System.Console.WriteLine("The number is{0}prime number.", IsPrimeNumber(number) ? " a " : " not a ");
            }

            System.Console.Write("Press any key to continue . . . ");
            System.Console.ReadLine();
        }

        public static bool IsPrimeNumber(int i_Number)
        {
            bool retVal = true;

            for (int i = 2; retVal && i < i_Number - 1; i++)
            {
                if (i_Number % i == 0)
                {
                    retVal = false;
                }
            }

            return retVal;
        }
    }
}
